package com.xh.bussiness.tiku.util;

import com.alibaba.fastjson.JSONObject;
import com.xh.bussiness.system.model.Dictionary;
import com.xh.bussiness.tiku.constant.QuestionConstant;
import com.xh.core.util.DateUtils;
import com.xh.core.util.MathUtils;
import com.xh.core.util.RegexUtils;
import com.xh.core.util.SendMsgUtils;
import com.xh.tools.question.data.dto.QuestionDTO;
import com.xh.tools.question.util.QuestionUtils;
import net.sourceforge.pinyin4j.PinyinHelper;
import org.apache.commons.collections4.map.LRUMap;

import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

/*
 * @Author daiwei
 * @Description
 * @Date 2019/4/8 13:35
 **/
public class Test {

    // 求阶乘的方法
    public static int factorial (int m) {
        if (m == 1) {
            // 这里要记住，return的是factorial方法，而不是结束执行if方法。
            return 1;
        }
        return m * factorial(m - 1);
    }

    /**
     * 二分查找
     *
     * @return
     */
    public static int binSearch(int[] array, int low, int high, int key) {
        System.out.println(low + "-" + high);

        if (low <= high) {
            int mind = (low + high) / 2;
            if (array[mind] == key) {
                return mind;
            } else if (key < array[mind]) {
                return binSearch(array, low, mind - 1, key);
            } else if (key > array[mind]) {
                return binSearch(array, mind + 1, high, key);
            }
        }
        return -1;
    }


    public static void main(String[] args) {




        /*

        int[] arry = {5,10,19,21,31,37,42,48,50,52};

        int i = binSearch(arry, 0, 10, 48);
        System.out.println(i);*/
        Map<String, Object> map = new HashMap<>();
        map.put("a", 1);
        map.put("b", 2);

        String s = JSONObject.toJSONString(map);
        System.out.println(s);


       /* Object s = "success";

        if (s != null && s.toString().equals("success")) {
            System.out.println(1);
        }

        Matcher matcher = RegexUtils.getMatcher("C．世界是不断变化发展的",QuestionConstant.REGEX_MATCH_RULE.XKW_OPTION_START_TAG);
        boolean b = matcher.find();
        System.out.println(b);


        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");

        String[] strings = list.toArray(new String[]{});
        System.out.println(1);

        Matcher mm = com.xh.tools.question.util.RegexUtils.getMatcher("1.sdfasd", com.xh.tools.question.constant.QuestionConstant.REGEX_MATCH_RULE.NUMBER);*/
        /*while (mm.find()) {
            String index = mm.group();
            System.out.println("#"+index);
        }*/

       /* if (mm.find()) {
            System.out.println("#"+mm.group());
        }*/

         /*   int n = 10;
            System.out.println(factorial(n));*/


       /* double numberRate = MathUtils.getNumberRate(MathUtils.divTwoNumberRoundHalfUp(2, 3, 2), 2);
        System.out.println(numberRate);
*/
      /*  SendMsgUtils.sendCheckCode("13716653360", "123");

        Calendar now = Calendar.getInstance();
        now.add(Calendar.DAY_OF_MONTH, -30);

        System.out.println(DateUtils.format(now.getTime(), "yyyy-MM-dd"));*/
        /* LRUMap<String, String> lruMap = new LRUMap<>(3);
        lruMap.put("a1", "1");
        lruMap.put("a2", "2");

        for (String s : lruMap.keySet()) {
            System.out.println(s);
        }
        lruMap.get("a2");
        for (String s : lruMap.keySet()) {
            System.out.println(s);
        }*/
      /*  String s = "math2,english2,math";
        Arrays.asList(s.split(",")).stream().distinct().collect(Collectors.toList()).forEach(item->{
            System.out.println(item);
        });
*/
       /* List<Dictionary> dictionaries = new ArrayList<>();
        Dictionary d1 = new Dictionary();
        d1.setName("2020");

        System.out.println(d1.getIsCheck());

        dictionaries.add(d1);

        dictionaries.stream().filter(item -> item.getName().equals("2020")).forEach(item -> item.setIsCheck(1));

        for (Dictionary dictionary : dictionaries) {
            System.out.println(dictionary.getIsCheck());
        }
*/


        //List<QuestionDTO> parse = QuestionUtils.parse("http://longwenhoutai.xiaohe.com/test/upload/202004/16/1587028913617418355.doc");
  /*      List<QuestionDTO> parse = QuestionUtils.parse("C:\\Users\\13716\\Desktop\\问题模板-完型填空.docx");
        System.out.println("1");*/

     /*   String s = "<b>【<b><b>2</b></b>】</b>阅读下列短文，选出最佳选项。";
        int i = s.indexOf("【");
        String startContent = s.substring(0, i);
        int endIndex = s.indexOf("】");
        String endContent = s.substring(endIndex+1);

        System.out.println(startContent+endContent);*/
        //   List<QuestionDTO> questionDTOS = QuestionUtils.parseHtml("<p>解答题</p><p>【】</p><p>假定英语课上老师要求同桌之间交换修改作文，请你修改你同桌写的以下作文。文中共有10处语言错误，每句中最多有两处。每处错误仅涉及一个单词的增加、删除或修改。</p><p>增加：在缺词处加一个漏字符号（∧），并在其下面写出该加的词。</p><p>删除：把多余的词用斜线（\\）划掉。</p><p>修改：在错的词下划一横线，并在该词下面写出修改后的词。</p><p>注意：1. 每处错误及其修改均仅限一词；</p><p>2. 只允许修改10处，多者（从第11处起）不计分。</p><p>Since I was a kid, I`ve considered different job I would like to do. First, I wanted to be a fireman, whose uniform looked so coolly. Then, when I was in the five grade, I wanted to be a teacher because I liked my English teacher too much. When I studied chemistry high school, I reconsidered mg goal or decided to be a doctor. They were two reasons for the decision. One was that I was amazing at the fact that a sick person could feel much more better after seeing a doctor. And the other is that I wanted to help people in need.&nbsp;</p><p><br/></p><p>答案：<img src=\"http://longwenhoutai.xiaohe.com/test/upload/ueditor/image/202003/24/1585044209511644715.png\" title=\"\" alt=\"\"/></p><p><br/></p><p><br/></p><p>解析：</p><p><br/></p>");
       /* String source="啊啊啊<span>ttt</span>";
        if(StringUtils.isEmpty(source)){
            return;
        }
        String result="";

        Document doc = Jsoup.parse(source);
        doc.outputSettings().prettyPrint(false);

        System.out.println(replaceUrlHost("http://publicdfs.exinlei.com/ueditor/image/84bec4f6-3169-4ff4-b650-9dc11a138bf5.jpg"));*/
    }

    private static String replaceUrlHost(String url) {
        String prtocal = url.startsWith("https") ? "https://" : "http://";
        String newHost = "cdn.tiku.xiaohe.com/";
        String result = url.replaceAll("^http(s)?:\\/\\/(.*?)\\/", newHost);
        return prtocal + result;
    }


}
